import pymysql

from user import User

conn = pymysql.connect(
    host='127.0.0.1',
    user='root',
    password='123456',
    port=3306,
    database='test'
)


def get(sql,num=-1):
    cursor = conn.cursor()
    cursor.execute(sql)
    if num == 1:
        return cursor.fetchone()
    return cursor.fetchall()


def insert(sql):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()


def delete(sql):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()


def update(sql):
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()

if __name__ == '__main__':
    userinfo = {
        'username':'123',
        'email':'2334'
    }
    # insert('insert into user values(1,"3","5")')
    print(get('select * from user where status = 1',1))
    # delete('delete from user')

